
$(top.hangge());

$(function() {
	
	  var url = {
			    listAccount: ctx+"/accountCheck/listAccount",
		        genCheckRecord:ctx+"/incomeAcct/genCheckRecord",
		        cancelRecord: ctx+"/incomeAcct/cancel",
		        appendRecord:ctx+"/incomeAcct/append",
		        listRecord:ctx+"/incomeAcct/getCheckList",
		        listItems:ctx+"/incomeAcct/listItems",
		        invalid:ctx+"/incomeAcct/invalid",
		        export:ctx+"/incomeAcct/export"
		    };
	
	 var qryTop = function () {
	        var param = $("#internalFeeManageform").serializeObject();
	        $(top.callService("post",url.listAccount,param,function (data) {
	        
	            $("#simple-table tbody").html(data);
	        },null,"html"));
	    };
	    qryTop();
    //日期框
    $('.date-picker').datepicker({autoclose: true,todayHighlight: true});

    //下拉框
    if(!ace.vars['touch']) {
        $('.chosen-select').chosen({allow_single_deselect:true});
        $(window)
            .off('resize.chosen')
            .on('resize.chosen', function() {
                $('.chosen-select').each(function() {
                    var $this = $(this);
                    $this.next().css({'width': $this.parent().width()});
                });
            }).trigger('resize.chosen');
        $(document).on('settings.ace.chosen', function(e, event_name, event_val) {
            if(event_name != 'sidebar_collapsed') return;
            $('.chosen-select').each(function() {
                var $this = $(this);
                $this.next().css({'width': $this.parent().width()});
            });
        });
        $('#chosen-multiple-style .btn').on('click', function(e){
            var target = $(this).find('input[type=radio]');
            var which = parseInt(target.val());
            if(which == 2) $('#form-field-select-4').addClass('tag-input-style');
            else $('#form-field-select-4').removeClass('tag-input-style');
        });
    }

    //复选框全选控制
    var active_class = 'active';
    $('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
        var th_checked = this.checked;//checkbox inside "TH" table header
        $(this).closest('table').find('tbody > tr').each(function(){
            var row = this;
            if(th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
            else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
        });
    });
    
 
});

function batchCheck(){
//	 var id = null;
	 var t = $("#simple-table").find("input[name='ids']:checked");
//	 var q = $("#simple-table").find("td[class='center']:checked");
//	 var array = $(".table tbody input[type=hidden]").map(function () {
//		 check_code = $.trim($(this).closest("tr").find("td:eq(11)").text()); 
//		 alert(check_code);
////		 alert(check_code);
//	 });
//	 var q= $('#simple-table > thead > tr > th input[type=checkbox]').eq(0);
//	 $('#simple-table > thead > tr > th input[type=checkbox]').eq(0).closest('table').find('tbody > tr').each(function(){
//         var row = this;
//          $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
////         else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
//     });
//	 var check_code = null;
//	 var array = $(".table tbody input[type=checkbox]:checked").map(function () {
//		 check_code = $.trim($(this).closest("tr").find("td:eq(1)").text()); 
//		 alert(check_code);
//	 });
	 
	     //获取table对像
//	    var rows=tb.rows;
//	      for(var i=0;i<rows.length;i++){    //--循环所有的行
//	        var cells=rows[i].cells;
////	        for(var j=1;j<cells.length;j++){   //--循环所有的列
////	           alert(cells[j].innerHTML);
////	 
////	        }
//	        alert(cells)
//	     }
	 var tb=document.getElementById("simple-table");
	    var ids = [];
	    for (i = 1; i < tb.rows.length; i++) {
            id = tb.rows[i].cells[0].getElementsByTagName("INPUT")[0].value;
            type = tb.rows[i].cells[11].getElementsByTagName("INPUT")[0].value
            var item = {id:id,type:type,bill_examine:"1"};
			 ids.push(item)
            
        }
	    var dataStr = JSON.stringify(ids);
//	 var ids = [];
//	 for(var i=0;i<=t.length-1;i++){
//		 if(t[i]!="undefined"){
//			 id=t[i].alt 
//			 var check_code = "";
//			 
////			 var type=$("#type").val();
//			 var item = {id:id,type:check_code,bill_examine:"1"};
//			 ids.push(item)
//		 }
//		
//	 }
//	 alert(ids);
	
	 
//	 var array = $(".table tbody input[type=checkbox]:checked").map(function () {
//		 id = $.trim($(this).closest("tr").find("td:eq(i)").text()); 
//		 alert(id)
////		 alert(check_code);
//	 });
	 
	 
//	 t = $(t).first();
//	 alert(t);
//	 var ipts = $(":checkbox:checked").parents("tr").find("input:text");
//	 alert(ipts);
	 
	 $.ajax({
         type: "POST",
         url: '../accountCheck/save',
         data: {dataStr:dataStr},
         dataType: 'json',
         cache: false,
         success: function (data) {
        	 alert("审核通过")
        	 window.location.reload();
        	 
         }
     });
}
function serch(){
//	top.jzts();
	$("#internalFeeManageform").attr("action","../accountCheck/index");
	$("#internalFeeManageform").submit();
	}
function batchVeto(){
//	var id = null;
//	 var array = $(".table tbody input[type=checkbox]:checked").map(function () {
//		 id = $.trim($(this).closest("tr").find("td:eq(1)").text()); 
//		 
//	 });
//	 var type=$("#type").val();
	 var tb=document.getElementById("simple-table");
	    var ids = [];
	    for (i = 1; i < tb.rows.length; i++) {
         id = tb.rows[i].cells[0].getElementsByTagName("INPUT")[0].value;
         type = tb.rows[i].cells[11].getElementsByTagName("INPUT")[0].value
         var item = {id:id,type:type,bill_examine:"0"};
			 ids.push(item)
         
     }
	    var dataStr = JSON.stringify(ids);
	 $.ajax({
         type: "POST",
         url: '../accountCheck/delete',
         data: {dataStr:dataStr},
         dataType: 'json',
         cache: false,
         success: function (data) {
        	 alert("否决成功")
        	 window.location.reload();
        	 
         }
     });
}
